package com.lanhai.fnstore.savestate;

import java.util.ArrayList; 
import java.util.List; 
 
/**
 * 状态队列
 * @author virus408
 *
 */
public class StateQueue {
	static List<StateData> queue = new ArrayList<StateData>();

	public static synchronized void Push( StateData item) {
		if(item==null||item.getName()==null||item.getName()=="") return ;
		
		boolean exist=false;
	   for(StateData data:queue) {
		   if(data.getType()==item.getType()&&data.getName().equals(item.getName())) {
			   data.setState(item.getState());
			   exist=true;
			   break; 
		   }
	   }
	   if(exist==false) {
		   queue.add(item);
	   }

	}

	public static synchronized List<StateData> Pop() {

		if (queue.isEmpty()) {
			return null;
		} 
		List<StateData> lis=new ArrayList<StateData>();
		for(StateData s:queue) {
			lis.add(s);
		}
		queue.clear();
		return lis;
	}
} 
